<cfcomponent output="false" extends="fileManager.core.ApplicationCore">
	
	<cfprocessingdirective pageencoding="utf-8" />
	<cfsetting showdebugoutput="false" />
	
    <cfcontent type="text/html; charset=utf-8" />
	
    <cfset setEncoding("url", "utf-8")>
    <cfset setEncoding("form", "utf-8")>
    
	<!--- Application settings --->
	<cfset this.name = "EasyBlog_#hash( cgi.HTTP_HOST )#">
	<cfset this.sessionManagement = true>
	<cfset this.sessionTimeout = createTimeSpan(0,0,30,0)>
	<cfset this.applicationTimeout = createTimeSpan(1,0,0,0)>
	
	<!--- Config  --->
	
	<cfset this.config = expandPath( 'config/config.ini.cfm' )/>
	<cfset this.basePath = getDirectoryFromPath( cgi.SCRIPT_NAME )/>
	<!--- Library mapping --->
	
	<cfset libs = expandPath( '#this.basePath#lib' ) />
	
	<cfset this.mappings["/cacheManagement"] = libs & "/cacheManagement/" />
	<cfset this.mappings["/notifyManager"] = libs & "/notifyManager/" />
	<cfset this.mappings["/coldspring"] = libs & "/coldspring/" />
	<cfset this.mappings["/ModelGlue"] = libs & "/ModelGlue/" />
	<cfset this.mappings["/it"] = libs & "/it/" />
	
	<cfset this.mappings["/plugins"] = '#this.basePath#/plugins' />
	<cfset this.mappings["/skin"] = '#this.basePath#/skin' />
	
	<!--- file manager mapping --->
	<cfset this.path = "/"/>
	<cfset this.mappings["/plugin"] = expandPath( '/fileManager/plugin/' ) />
	
	<!--- Application events --->
	
	<cffunction name="onSessionStart" output="false">
		
		<cfset invokeSessionEvent("modelglue.onSessionStart", session, application) />
		
		<cfset super.onSessionStart( argumentCollection=arguments ) />

	</cffunction>
	
	<cffunction name="onSessionEnd" output="false">
		<cfargument name="sessionScope" type="struct" required="true">
		<cfargument name="appScope" 	type="struct" required="false">
	
		<cfset invokeSessionEvent( "modelglue.onSessionEnd", arguments.sessionScope, arguments.appScope ) />
		
		<cfset super.onSessionEnd( argumentCollection=arguments ) />
	</cffunction>
	
	<cffunction name="onRequestStart">
	    
	    <cfset setLocale( "Italian (Standard)" ) />
	    
	    <cfif structKeyExists( url, 'init')>
			<cfset onApplicationStart() />
		</cfif>
		
		<cfset super.onRequestStart( argumentCollection=arguments ) />
	</cffunction>
	
	<cffunction name="onApplicationStart">
	
		<cfset trace( type="Information", text="Application start...") />
		
		<cfif not structKeyExists( application, '_easyBlog' ) or structKeyExists( url, 'reload' )>
			
			<cfset run() />
		
		</cfif>
		
		<cfscript>
		super.onApplicationStart( argumentCollection=arguments );
		</cfscript>
		
	</cffunction>
	
	<cffunction name="store" access="public" returntype="void" >
		<cfargument name="framework" type="Any" required="true" />
		
		<cflock type="exclusive" scope="Application" timeout="180">
			
			<cfset application['_easyBlog'] = arguments.framework  />
		
		</cflock>
		
	</cffunction>
	
	<!--- Private --->

	<cffunction name="run" access="private" >
		<cfscript>
		var bootStrapp = "";
		trace( type="Information", text="Initialize bootstrap...");
		bootStrapp = createObject( 'component','it.millemultimedia.easyBlog.loading.EasyBlogBootstrapper').init( this );
		trace( type="Information", text="Run bootstrap...")
		bootStrapp.run();
		</cfscript>
	</cffunction>
	
	<cffunction name="invokeSessionEvent" output="false" access="private">
		<cfargument name="eventName" />
		<cfargument name="sessionScope" />
		<cfargument name="appScope" />
		
		<cfset var mgInstances = createObject("component", "ModelGlue.Util.ModelGlueFrameworkLocator").findInScope(appScope) />
		<cfset var values = structNew() />
		<cfset var i = "" />
		
		<cfset values.sessionScope = arguments.sessionScope />
		
		<cfloop from="1" to="#arrayLen(mgInstances)#" index="i">
			<cfset mgInstances[i].executeEvent(arguments.eventName, values) />
		</cfloop>
		
	</cffunction>
	
</cfcomponent>